using System;

namespace Bookvar.ObjectModel.Actions
{
    /// <summary>
    /// This action adds a floating topic.
    /// </summary>
    public class AddFloatingTopicAction : MindmapTopicActionBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AddFloatingTopicAction"/> class.
        /// </summary>
        public AddFloatingTopicAction()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="AddFloatingTopicAction"/> class.
        /// </summary>
        /// <param name="topic">The topic.</param>
        /// <param name="mindmap">The mindmap.</param>
        public AddFloatingTopicAction( Topic topic, MindMap mindmap ) : base( topic, mindmap )
        {
        }

        /// <summary>
        /// Executes the action: adds the topic as a floating in the provided mind map.
        /// </summary>
        /// <exception cref="InvalidOperationException">if the topic for this action is not set.</exception>
        public override void Execute()
        {
            base.Execute();

            Mindmap.FloatingTopics.Add( Topic );
        }

        /// <summary>
        /// Undoes this action.
        /// </summary>
        /// <exception cref="InvalidOperationException">if the topic for this action is not set.</exception>
        public override void Undo()
        {
            base.Undo();

            Mindmap.FloatingTopics.Remove( Topic );
        }
    }
}